package interview.hw_od;

import java.util.HashMap;
import java.util.Scanner;

/**
 * 报文回路 https://codefun2000.com/p/P1329
 */
public class MessageCheck {

    /**
     * 思路：用map记录报文，扫描到回路则消除，最后若map为空则无异常
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 1;i <= num;i++) {
            int d1 = sc.nextInt(), d2 = sc.nextInt();
            if (map.get(d2) != null && map.get(d2).equals(d1))
                map.remove(d2);
            else map.put(d1, d2);
        }
        System.out.println(map.isEmpty());
    }
}
